<%--
  Created by IntelliJ IDEA.
  User: FENG1
  Date: 2022/5/9
  Time: 15:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>增加修改页</title>
    <link rel="stylesheet" href="static/component/pear/css/pear.css" />
</head>
<body>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <c:if test="${sign=='add'}" var="f">
                <input type="hidden" name="sign" value="add">
                <div class="layui-form-item">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="departmentName" lay-verify="title" autocomplete="off" placeholder="请输入部门名称"
                               class="layui-input">
                    </div>
                </div>
            </c:if>
            <c:if test="${!f}">
                <input type="hidden" name="departmentId" value="${dep.departmentId}">
                <input type="hidden" name="sign" value="up">
                <div class="layui-form-item">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="departmentName" value="${dep.departmentName}" lay-verify="title" autocomplete="off" placeholder="请输入部门名称"
                               class="layui-input">
                    </div>
                </div>
            </c:if>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function() {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(user-save)', function(data) {
            let depName = $("[name='departmentName']").val();
            if(depName==""||depName==null){
                layer.msg("部门名称不能为空！");
                return false;
            }
            $.ajax({
                url: 'department/allupDep',
                data: data.field,
                type: 'post',
                success: function(result) {
                    if (result.success) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("department-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</body>
</html>